package first.progr.tc;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import java.util.Random;

import org.testng.annotations.Test;

import first.progr.utils.SortedListOf;

public class GroupModificationTests extends TestBase {
	
	@Test(dataProvider = "randomValidGroupGenerator")
	public void modifySomeGroup(GroupData gr) throws Exception {
		// Save old groups state
		SortedListOf<GroupData> oldGroupsList = app.getGroupHelper().getGroups();
		
		Random rnd = new Random();
		int index = rnd.nextInt(oldGroupsList.size()-1);
		
		// Actions
		app.getGroupHelper().modifyGroup(index, gr); 
		
		// Save new groups state
		SortedListOf<GroupData> newGroupsList = app.getGroupHelper().getGroups();
	    
	    // Compare states of lists
		assertThat(newGroupsList, equalTo(oldGroupsList.without(index).withAdded(gr)));
	}		
}
